package com.team.student.controller;

import com.team.student.entity.Student;
import com.team.student.service.StudentService;
import com.team.student.service.impl.StudentServiceImpl;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class StudentController {
    StudentService ss= new StudentServiceImpl();
    @RequestMapping("/showStudent")  //查所有
    public String ShowStudent(Model m){

       List<Student> list= ss.getStudent();
       m.addAttribute("list",list);
        return "index";
    }

    @RequestMapping("/addStudent")  //添加
    public String addStudent(Student student){
        int a=ss.addStudent(student);
        if (a>0)
            return "redirect:showStudent";
        else
            return "redirect:addStudent.jsp";
    }

    @RequestMapping("/delectStudent") //删除
    public String delectStudent(Integer xh){
       int b= ss.deleteStudent(xh);
        if (b>0)
            return "redirect:showStudent";
        else
            return "redirect:showStudent";
    }

    @RequestMapping("/selectOneStu") //查单条
    public String selectOneStu(Integer xh,Model m){
      Student stu= ss.selectStudent(xh);
      m.addAttribute("stu",stu);
        return "updStudent";
    }

    @RequestMapping("/updStudent")  //修改
    public String updStudent(Student stu){
        int d=ss.updStudent(stu);
        if (d>0)
            return "redirect:showStudent";
        else
            return "redirect:selectOneStu";
    }

}
